package org.sgx.gwteditorstest.client;

import org.sgx.gwteditors.client.impl1.EditorFramework1;
import org.sgx.gwteditors.client.impl1.complex.PropertyHaverEditor2;
import org.sgx.gwteditors.client.impl1.edbean.EditableBean;
import org.sgx.gwteditors.client.impl1.edbean.UseEditor;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * In this test we customize a bean's editor properties using the @UseEditorAnnotation. Among other things it let us define custom property labels and custom property editors.
 * 
 * @author sg
 * 
 */
public class BeanEditorTestWithAnnotations {

	public void test(Panel parent) {
		new EditorFramework1().start();

		IntegersBean1 ib1 = GWT.create(IntegersBean1.class);
		ib1.setImageUrl("http://www.freeimageslive.com/galleries/sports/lifestyle/preview/checkers_game_PC238712.jpg");
		ib1.setLink("http://en.wikipedia.org/wiki/Thus_Spoke_Zarathustra");
		ib1.setResume("<p>hello <b>world</b></p>"); 
		
//		System.out.println("Editor id for property 'meaureTwo' is: "
//				+ ib1.getProperties().get("measureTwo").getEditorId());

		VerticalPanel vp = new VerticalPanel();
		vp.setWidth("100%");
		parent.add(vp); // make sure the editor parent (vp) is attached to the dom before using the editor

		PropertyHaverEditor2<IntegersBean1> ed = new PropertyHaverEditor2<IntegersBean1>();
		vp.add(ed.getWidget());

		ed.load(ib1);

	}

	// THE EDITABLE BEAN :

	/**
	 * a ed bean that uses annotations to indicate different integer editors.
	 * 
	 * @author sg
	 * 
	 */
	public static abstract class IntegersBean1 implements EditableBean {

		Integer measureOne, measureTwo;

		String link, imageUrl, resume;

		public IntegersBean1() {
			measureOne = 1;
			measureTwo = 2;
		}

		@UseEditor(description = "de ser positivo el sol es 9*pi mayor.", editorName = "org.sgx.gwteditors.client.impl1.simple.IntegerEditorEntry2", label = "Coeficiente intelectual de la luna")
		public Integer getMeasureOne() {
			return measureOne;
		}

		public void setMeasureOne(Integer measureOne) {
			this.measureOne = measureOne;
		}

		@UseEditor(description = "siempre y cuando sea una playa ecuatorial", editorName = "org.sgx.gwteditors.client.impl1.simple.IntegerEditorEntry", label = "Cantidad de pingüinos en la arena")
		public Integer getMeasureTwo() {
			return measureTwo;
		}

		public void setMeasureTwo(Integer measureTwo) {
			this.measureTwo = measureTwo;
		}

		@UseEditor(description = "demonstrating the LinkEditor", editorName = "org.sgx.gwteditors.client.impl1.misc.LinkEditor", label = "Enlace internetoso", config = "linkText: 'Un buen libro'")
		public String getLink() {
			return link;
		}
		public void setLink(String link) {
			this.link = link;
		}

		@UseEditor(description = "demonstrating the ImageUrlEditor", 
				editorName = "org.sgx.gwteditors.client.impl1.misc.ImageUrlEditor", 
				label = "Imagen representativa", 
				config = "editable:true, height: '50px'")
		public String getImageUrl() {
			return imageUrl;
		}
		public void setImageUrl(String imageUrl) {
			this.imageUrl = imageUrl;
		}
		@UseEditor(description = "demonstrating the RichTextEditor", 
				editorName = "org.sgx.gwteditors.client.impl1.misc.RichTextEditor", 
				label = "Resume in rich html format")
		public String getResume() {
			return resume;
		}
		public void setResume(String resume) {
			this.resume = resume;
		}

	}

}
